<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/system/common/head.jsp"%>
<script type="text/javascript" src="asserts/system/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="asserts/plugins/easyui/plugins/jquery-easyui-datagridview/datagrid-detailview.js"></script>
<style type="text/css">
    .errormsg {
        font-family: "微软雅黑";
        color: #F30;
    }
</style>
<body>
<div class="outer">

    <form id="adform">
        <div class="formDiv">
            <table width="" border="0">
                <tr>
                    <form:input id = "hiddenImgValue1" path="worksImg1" type="hidden" />
                    <form:input id = "hiddenImgValue2" path="worksImg2" type="hidden" />
                 <%--   <form:input id = "hiddenImgValue3" path="worksImg3" type="hidden" />--%>
                   <%-- <td align="right">作品名称：</td>
                    <td align="left"><form:input path="worksName" /><span
                            class="errormsg"><form:errors path="worksName" /></span></td>
                </tr>
                <tr>
                    <td align="right">作品说明：</td>
                    <td align="left"><form:textarea path="worksRemark" cols="30"
                                                    rows="10" /><span class="errormsg"><form:errors
                            path="worksRemark" /></span></td>
                </tr>--%>
                <tr>
                    <td align="right">大图：</td>
                    <td align="left">
                        <img src="asserts/system/images/loading.gif" id="loading1" style="display: none;">
                        <img id="realPic1" src="asserts/system/images/pic.jpg"  width="123" height="89"/>
                        <input name="realPicFile1" id="realPicFile1" type="file" onchange="ajaxFileUpload('realPicFile1','realPic1','hiddenImgValue1','loading1')" style='display:none'/>
                        <input type=button onclick="upImg('realPicFile1')" value="上传" />
                        <span class="errormsg">
                                <form:errors path="worksImg1" />
                            </span>
                    </td>
                </tr>
                <tr>
                    <td align="right">小图：</td>
                    <td align="left">
                        <img src="asserts/system/images/loading.gif" id="loading2" style="display: none;">
                        <img id="realPic2" src="asserts/system/images/pic.jpg"  width="123" height="89"/>
                        <input name="realPicFile2" id="realPicFile2" type="file" onchange="ajaxFileUpload('realPicFile2','realPic2','hiddenImgValue2','loading2')" style='display:none'/>
                        <input type=button onclick="upImg('realPicFile2')" value="上传" />
                        <span class="errormsg">
                                <form:errors path="worksImg2" />
                            </span>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <a  class="easyui-linkbutton myLink" iconCls="icon-ok" style="margin-left:20px;"
                            onclick="addAdvInfo()">提交 </a>
                       </td>
                </tr>

            </table>
        </div>
    </form>
</div>
<div id="errorMsgDiv"></div>
<script>
    jQuery(document).ready(function() {
      //  App.init(); // initlayout and core plugins
    });
</script>
<script>
    function upImg(fileID){
        $("#"+fileID).click();
    }

    function ajaxFileUpload(fileID,imgID,hiddenImgValue,loadingId) {
        /*var file = $("#"+hiddenImgValue).val();
        if(!/\.(jpg|png|JPG|PNG)$/.test(file)){
            Error("不支持的图片格式.图片类型必须是.jpg,png格式.");
            return false;
        }*/
        //$("#"+loadingId).show();
        $("#" + imgID).attr("src", "asserts/system/images/loading.gif");
        $.ajaxFileUpload({
            url : 'community/adv/uploadOnePic?inputId='+fileID,
            secureuri : false,
            fileElementId : fileID,
            dataType : 'json',
            success : function(data, status){

                if(data.status != 1){
                    $.messager.alert('提示:', data.msg, 'error');
                    $("#" + imgID).attr("src", "asserts/system/images/pic.jpg");
                }else {
                    $("#" + imgID).attr("src", data.data);
                    $("#" + hiddenImgValue).val(data.data);
                }
                //$(this).val(data.result);
                //console.log($('#realPicFile'));
            },
            error : function(data, status, e){
                $("#" + imgID).attr("src", "asserts/system/images/pic.jpg");
                $.messager.alert('提示:', e.message, 'error');
                //Error(e);
            }
        });
        return true;
    }

    function checkFileValue(hiddenImgValue){
       var file = $("#"+hiddenImgValue).val();
        if(file.length == 0){
            $.messager.alert('提示信息', '请上传大图');
            return false;
        }
        if(!/\.(jpg|png|JPG|PNG)$/.test(file)){
            $.messager.alert('提示信息', "不支持的图片格式.图片类型必须是.jpg,png格式.");
            return false;
        }
        return true;
    }

    /**
     * 提交广告图片
     */
    function addAdvInfo() {
      if(!checkFileValue("hiddenImgValue1")){
          return;
      }
        if(!checkFileValue("hiddenImgValue2")){
            return;
        }
        var img1 = $("#hiddenImgValue1").val();
        var img2 = $("#hiddenImgValue2").val();
        var data = {"hiddenImgValue1":img1,"hiddenImgValue2":img2}
        load();
        postAjax({
            url: 'community/adv/addadv',
            data: data,
            callback: function (result) {
                disLoad();
                if (result.status == 1) {
                    $.messager.alert("提示信息", (result && result.msg)?result.msg:'操作成功', 'info', function () {
                        var el =  parent.window.document.getElementById('menuAddFrame');
                        var iframe = el.contentWindow;
                        if(el){
                            el.src = 'about:blank';
                            try{
                                iframe.document.write('');
                                iframe.document.clear();
                            }catch(e){};

                        }
                                parent.dataGrid.datagrid('reload');


                    });
                }else{
                    $.messager.alert('提示信息', (result && result.msg)?result.msg:'操作失败', function(r){
                    });
                }
            },
        });
    }
</script>
</body>
</html>